<?php

App::uses('AppController', 'Controller');

class ContactController extends AppController {

	public $uses = array('Contact');

	public function index() {

		$list = $this->Contact->find('all', array('conditions' => array('delete_flg' => '0'), 'order' => 'read_status ASC'));
		$this->set('list', $list);
	}
	
	public function delete() {
	
		$id = $_GET['id'];
	
		$data = array('id' => $id, 'delete_flg' => '1');
	
		// This will update Recipe with id 10
		$this->Contact->save($data);
	
		return $this->redirect('/contact');
	}
	
	public function detail() {	
						
		$id = $_GET['id'];
		
		$this->updateView($id);
		
		$data = $this->Contact->find('first', array('conditions' => array('id' => $id, 'delete_flg' => '0')));
		$this->set('data', $data);
	
	}
	
	public function updateView($id) {
		
		$data = array('id' => $id, 'read_status' => '1');
		
		// This will update Recipe with id 10
		$this->Contact->save($data);
		
		$conditions = array('delete_flg' => '0', 'read_status' => '0');
		$total = $this->Contact->find('count', array('conditions' => $conditions));
		
		$this->set('total', $total);
	}
}
